package com.dome.mvp.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.Toast;

import com.dome.mvp.BR;
import com.dome.mvp.R;
import com.dome.mvp.adapter.MainAdapter;
import com.dome.mvp.base.BaseActivity;
import com.dome.mvp.bean.MainBean;
import com.dome.mvp.databinding.ActivityMainBinding;
import com.dome.mvp.presenter.MainPresenter;
import com.dome.mvp.view.IMainView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity<IMainView, MainPresenter, ActivityMainBinding> implements IMainView {

    private MainAdapter mainAdapter;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_main;
    }

    @Nullable
    @Override
    public MainPresenter createPresenter() {
        return new MainPresenter();
    }

    @Override
    public void init() {
        super.init();
        mainAdapter = new MainAdapter(getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_SET_USER_VISIBLE_HINT);
        getBind().mainFragment.setAdapter(mainAdapter);
        // 禁止滑动
        getBind().mainFragment.setSlidingEnable(false);
        getBind().square.setChecked(true);
        presenter.getLiveData().observe(this, fragments -> {
            mainAdapter.setList(fragments);
            getBind().mainFragment.setCurrentItem(1);
        });
    }

    @Override
    public int variableId() {
        return BR.data;
    }


    @Override
    public void showFragment(int index) {
        getBind().mainFragment.setCurrentItem(index);
    }
}